<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <link rel="stylesheet" href="css/public.css" type="text/css">
    <link rel="stylesheet" href="css/register.css">
</head>
<body>
    <div class="header">
        <div class="header_all">
                <div class="header_left"><img src="image/logo.png" alt="" srcset=""></div>
                <div class="header_right">
                    <a href="index.html">寺库首页</a>
                    <a href="#">收藏寺库</a>
                    <a href="#">寺库APP</a>
                </div>
        </div>    
    </div>
    <div class="center">
        <div class="center_all">
            <div class="center_left"><img src="image/left.jpg" alt=""></div>
            <div class="center_right">
                <div class="center_right_reg">
                    <div class="center_right_regs">
                            <div class="name">
                                    <label>用户名:</label><span class="spu" id="spu">请输入手机号或者邮箱</span>
                                    <input type="text" name="username" id="username">
                            </div>
                            <div class="password">
                                    <label>密码:</label><span class="spp" id="spp"></span>
                                    <input type="password" name="password" id="password" >
                            </div>
                            <div class="password">
                                    <label>确认密码:</label><span class="sppa" id="sppa"></span>
                                    <input type="password" name="password" id="passwords" >
                            </div>
                            <div class="ch"><input type="checkbox" style="vertical-align: middle"><span>贵宾邀请码</span></div>
                            <div class="zc" id="zc">立即注册</div>
                            <div class="che">
                                <input  type="checkbox"  id="checkin8" checked="checked" style="vertical-align: middle"/>
                                <label for="checkin8">我已阅读并同意《寺库网用户注册协议》</label>
                            </div>
                            <div class="vip"><span>已经是寺库会员？<a href="login.html">立即登录</a></span></div>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="bottom_top">
            <ul>
                
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">诗库奢饰品养护</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
    
           
        </div>
        <div class="bottom_bottom">
            <p>统一社会信用代码：91110102689248179K</p>
            <p><img src="/image/ga.png"><a href="#">京公安备11010102001392</a></p>
            <p>京ICP证110119号&nbsp;京ICP备09084709号-3</p>
            <p>IS09001中国质量管理体系认证</p><br>
            <p>COPYRIGHT&COPY;2010-2017北京寺库商贸有限公司&nbsp;版却所有</p><br>
            <a href="#" class="low"><img src="image/1.jpg"></a>
            <a href="#" class="low"><img src="image/2.jpg"></a>
            <a href="#" class="low"><img src="image/3.jpg"></a>
            <a href="#" class="low"><img src="image/4.jpg"></a>
            <a href="#" class="low"><img src="image/5.jpg"></a>
        </div>
    </div>
</body>
</html>
<script src="js/public.js"></script>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
    var arr0 = 0;
    var arr1 = 0;
    var arr2 = 0;
    $id("username").onclick = function(){
        $id("username").style.border = "1px solid red";
        $id("username").onblur = function(){
            var uname = $id("username").value;
            var res = /^1[34578]\d{9}$/;
            var resa = /^\w+@\w+(\.\w+)+$/;
            if( !isNaN(uname)){
                if(!res.test(uname)){
                    $id("spu").innerHTML = "请输入正确的手机号或者邮箱";
                    $id("spu").style.color = "red";
                    $id("spu").style.fontWeight = "800"
                }else{
                    arr0 = 1;
                }
            }else{
                if(!resa.test(uname)){
                    $id("spu").innerHTML = "请输入正确的手机号或者邮箱";
                    $id("spu").style.color = "red";
                    $id("spu").style.fontWeight = "800"
                }else{
                    arr0 = 1;
                }
            }
        }
    }
    $id("password").onclick = function(){
        $id("password").style.border = "1px solid red";
            $id("password").onblur = function(){
                var password = $id("password").value;
                var res1 = /^\w{6,16}$/;
                    if(!res1.test(password)){
                        $id("spp").innerHTML = "请输入正确的密码格式";
                        $id("spp").style.color = "red";
                        $id("spp").style.fontWeight = "800"
                    }else{
                        arr1 = 1;
                    } 
             }    
    }
    $id("passwords").onclick = function(){
        $id("passwords").style.border = "1px solid red";
            $id("passwords").onblur = function(){
                var passwords = $id("passwords").value;
                var password = $id("password").value;
                    if(password != passwords ){
                        $id("sppa").innerHTML = "两次密码输入不一致，请重新输入"; 
                        
                    }else{
                        arr2 = 1;
                    }  
                }
    }
    $id("zc").onclick = function(){
        if (arr0*arr1*arr2 == 1 ){
            var uname = $id("username").value;
            var password = $id("password").value;
            var url = `http://jx.xuzhixiang.top/ap/api/reg.php?username=${uname}&password=${password}`;
            $.ajax({
                url:url,
                type:'get',
                success:function (res) {
                    obj=eval("("+res+")");
                    if( obj.code == 1){
                        //console.log(obj.code)
                        alert("注册成功!")
                        window.location.href = "login.html";
                    }
                },
                error:function (error) {
                    console.log(error);
                }
            })
            
        }
    }
</script>